import { all, info, save, publish, vote, result } from '@/api/vote'

const actions = {
    all({ commit }, params) {
        const { page, pageSize, title } = params
        return new Promise((resolve, reject) => {
            all({ page: page, pageSize: pageSize, title: title }).then(response => {
                resolve(response.data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    info({ commit }, params) {
        const { id } = params
        return new Promise((resolve, reject) => {
            info({ id: id }).then(response => {
                resolve(response.data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    save({ commit }, data) {
        return new Promise((resolve, reject) => {
            save(data).then(response => {
                resolve(response.data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    publish({ commit }, data) {
        return new Promise((resolve, reject) => {
            publish(data).then(response => {
                resolve(response.data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    vote({ commit }, data) {
        return new Promise((resolve, reject) => {
            vote(data).then(response => {
                resolve(response.data)
            }).catch(error => {
                reject(error)
            })
        })
    },
    result({ commit }, params) {
        const { id } = params
        return new Promise((resolve, reject) => {
            result({id: id}).then(response => {
                resolve(response.data)
            }).catch(error => {
                reject(error)
            })
        })
    },
}

export default {
    namespaced: true,
    actions
}  